<!--
Author: Quan Van Sinh
Email : sinhvnb@vietnambiz.com
Mobile: 0972405165
-->


<?php 
if(isset($_REQUEST['submitFrmSendNewsletter']) && trim($_REQUEST['submitFrmSendNewsletter'])!='') {
    $content = $_REQUEST['content'];
    $subject = $_REQUEST['subject'];
    $mails = getNewsletterToSend();
    include SITE_BASE_DIR.'/sendmail/class.phpmailer.php';
    $mail = new PHPMailer();
    ini_set('max_execution_time', 300);//second
    while($rs=$db->fetch_array($mails)) {
        sendNewsletter($rs['email'],$subject,$content);
    }
    ini_set('max_execution_time', 60);//second
}
$class_newsletter_sendMail = 'class="active"';
include ADMIN_INCLUDE_DIR."/header.php";
?>
<script type="text/javascript" language="javascript">
    var popupImageParams = '&forModule=news&position=content';
    $(document).ready(function (){
        CKEDITOR.config.resize_enabled = false;
        CKEDITOR.config.width = 600;
        CKEDITOR.config.height = 400;
        CKEDITOR.replace( 'content',
        {
            toolbar :
                [['Maximize', '-','Format','Font','FontSize','-','TextColor','BGColor','-','Bold','Italic','Underline','Strike','-','NumberedList','BulletedList','-','Outdent','Indent','Blockquote','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock', '-','Image','Table','-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink' ]]
        });

    });

    function checkSendMailCondition(){
        if($('#subject').val()=='' || $('#subject').val()==' '){
            alert("Bạn chưa nhập tiêu đề thư!");
            return false;
        }else{
            if(CKEDITOR.instances.content.getData()=='' || CKEDITOR.instances.content.getData()==' '){
                alert("Bạn chưa nhập nội dung thư!");
                return false;
            }
        }
        return true;
    }
</script>
<div class="container_l">
    <div class="title_user"><img src="images/icon4.gif" />Gửi thư</div>
    <div class="table_user">
        <?php
        show_error();
        show_success();
        ?>
        <div class="spacer1"><span></span></div>
        <form name="formSendNewsletter" method="post" action="" onsubmit="return checkSendMailCondition();">
            <div class="lineaddnew">
                <div class="lineform">
                    <div class="divlabel">Tiêu đề:</div>
                    <div class="divform">
                        <input type="hidden" name="module" value="newsletter"/>
                        <input type="hidden" name="action" value="sendMail"/>
                        <input type="text" id="subject" name="subject" style="width: 600px;"/>
                    </div>
                </div>
                <div class="lineform">
                    <div class="divlabel">Nội dung thư:</div>
                    <div class="divform">
                        <input type="hidden" name="module" value="newsletter"/>
                        <input type="hidden" name="action" value="sendMail"/>
                        <textarea name="content" id="content" cols="2" rows="10"></textarea>
                    </div>
                </div>
                <div class="linesubmit">
                    <input type="submit" name="submitFrmSendNewsletter" value="Gửi thư" class="button" />
                </div>
                <div class="spacer1"><span></span></div>
            </div>
        </form>
        <div class="spacer1"><span></span></div>

    </div>
</div>

<?php
include "inc/right.php";
include ADMIN_INCLUDE_DIR."/footer.php";
?>